package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.BasicQuiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface BasicQuizRepository extends JpaRepository<BasicQuiz, Long>,JpaSpecificationExecutor<BasicQuiz> {

    Optional<BasicQuiz> findByIdAndIsAvailableIsTrue(Long id);

    List<BasicQuiz> findAllByIsAvailableIsTrueAndIdIn(List<Long> ids);

    @Query(value = "SELECT  b FROM BasicQuiz b JOIN b.tags t WHERE  b.isAvailable=true AND t.name in :names")
    List<BasicQuiz> findBasicQuizzesByTags(@Param("names") List<String> names);

    List<BasicQuiz> findByIdIn(List<Long> ids);
}

